﻿using System;
using System.Windows;
#if WPF
using System.Windows.Data;
using System.Windows.Shapes;
#else
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Shapes;
using Windows.UI.Xaml.Data;
using Windows.Foundation;
#endif
namespace Eternal.DataVisualization
{
    public class StepLineSeries : AxisType
    {
        protected internal override void OnDrawSegment()
        {
            base.OnDrawSegment();
            SegmentPanel.Children.Clear();
            var line = new Polyline();
            SegmentPanel.Children.Add(line);
            ApplyBrush(line, 0);
            var dataCount = ActualXData.Count - 1;
            for (var i = 0; i < dataCount; i++)
            {
                line.Points.Add(new Point(ValueToCoordianteXAxis(i), ValueToCoordianteYAxis(ActualYData[i])));
                line.Points.Add(new Point(ValueToCoordianteXAxis(i + 1), ValueToCoordianteYAxis(ActualYData[i])));
                line.Points.Add(new Point(ValueToCoordianteXAxis(i + 1), ValueToCoordianteYAxis(ActualYData[i + 1])));
            }
        }

        protected internal override void ApplyBrush(Shape element, int index)
        {
            element.StrokeThickness = StrokeThickness;
            element.Stroke = SegmentBrush ?? Area.GetBrush(index);
        }
    }
}
